<?php
namespace app\http;

use think\worker\Server;

class Websocket extends Server
{
	protected $socket = 'Websocket://0.0.0.0:3333';
	protected $option = ['name'=>'juzi38hao','count'=>2];

	public function onMessage($connection,$data)
	{
		echo "客户端发来信息：".$data."";
		//服务端响应后回调给用户端发送信息
		$connection->send("服务端已收到你的".$data."来信");
	}
	
	public function onWorkerStart($worker){
		echo 'websoket服务启动成功'."\n";
	}
	
	public function onConnect($connection){
		$connection->send("握手成功，链接已建立，服务端发来贺电");
		echo $connection->getRemoteIp()."的客户端链接上了". "\n";
	}
	
	public function onClose($connection){
		echo 'websoket服务端关闭'."\n";
	}
	
}
